package com.qn;

import com.qn.strategy.ICouponDiscount;
import com.qn.strategy.eums.EnumPromotionType;
import com.qn.strategy.factory.HandleServiceStrategyFactory;
import com.qn.strategy.factory.PromotionTypeServiceStrategyFactory;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
@Slf4j
class Strategy {

    @Test
    public void test_zj() {
        String vipType = "ZJ";
        //指定用户类型，获得相对应的策略
        ICouponDiscount strategy = PromotionTypeServiceStrategyFactory.getByUserType(vipType);
        // 直减；100-10，商品100元
        BigDecimal discountAmount = strategy.discountAmount(10D, new BigDecimal(100));
        log.info("测试结果：直减优惠后金额 {}", discountAmount);
    }

    @Test
    public void test_mj() {
        String vipType = "MJ";
        //指定用户类型，获得相对应的策略
        ICouponDiscount strategy = HandleServiceStrategyFactory.getHandleByCommand(vipType);
//        ICouponDiscount strategy = PromotionTypeServiceStrategyFactory.getByUserType(vipType);

        // 满100减10，商品100元
        Map<String, String> mapReq = new HashMap<String, String>();
        mapReq.put("x", "100");
        mapReq.put("n", "10");
        BigDecimal discountAmount = strategy.discountAmount(mapReq, new BigDecimal(100));
        log.info("测试结果：满减优惠后金额 {}", discountAmount);
    }

    @Test
    public void test_zk() {
        String vipType = "ZK";
        //指定用户类型，获得相对应的策略
        ICouponDiscount strategy = PromotionTypeServiceStrategyFactory.getByUserType(vipType);

        // 折扣9折，商品100元
        BigDecimal discountAmount = strategy.discountAmount(0.9D, new BigDecimal(100));
        log.info("测试结果：折扣9折后金额 {}", discountAmount);
    }

    @Test
    public void test_nyg() {
        String vipType = "NY";
        // 指定用户类型，获得相对应的策略
        ICouponDiscount strategy = PromotionTypeServiceStrategyFactory.getByUserType(EnumPromotionType.NY.getValue());

        // n元购；100-10，商品100元
        BigDecimal discountAmount = strategy.discountAmount(90D, new BigDecimal(100));
        log.info("测试结果：n元购优惠后金额 {}", discountAmount);
    }

}
